---
import Layout from "../layouts/Layout.astro"
import Header from "../components/Header.astro"
import Footer from "../components/Footer.astro"
import { Content, frontmatter } from "@content/portfolio.md"
import { frontmatter as about } from "@content/about.md"
import Button from "../lib/Button.astro"
import { sortProjects } from "../api/projects"

const { title, description, link } = frontmatter

const projects = sortProjects(await Astro.glob("../content/projects/*.md"))
---

<Layout title={title}>
    <Fragment slot="seo">
        <meta name="description" content={description} />
    </Fragment>
    <Header class="portfolio__header" />
    <div class="hero">
        <div class="container">
            <h1 class="page__title">{title}</h1>
            <p class="page__subtitle">{about.fullname}</p>

            <Button href={link}>Посмотреть на GitHub</Button>
        </div>
    </div>
    <div class="container">
        <main class="page__content" role="main">
            <h2>Проекты</h2>
            <ul class="projects">
                {
                    projects
                        .filter(({ frontmatter: { time } }) => time)
                        .map(({ frontmatter: { link, title, time } }) => (
                            <li class="project">
                                <a href={link}>{title}</a>
                                <span class="project__time">{time}</span>
                            </li>
                        ))
                }
            </ul>
            <Content />
        </main>
        <hr class="horizontal-line" />
        <Footer class="portfolio__footer" />
    </div>
</Layout>

<style>
    :root {
        --text-color: #606c71;
        --background-color: white;
        --color: black;
        --link-color: #13599f;
        --link-visited-color: #7f387b;
        --accent-color: #319957;
    }
    @media (prefers-color-scheme: dark) {
        :root {
            --background-color: #2a2a2a;
            --color: white;
            --link-color: #378fe6;
            --link-visited-color: #8f37e6;
        }
    }
    .project {
        display: flex;
        gap: 1em;
    }
    body {
        background-color: var(--background-color);
        color: var(--color);
    }
    .hero {
        color: white;
        background-color: hsl(150, 76%, 27%);
        background-image: linear-gradient(120deg, #155799, #159957);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 6em 0;
        min-height: 50vh;
    }
    .hero .container {
        display: contents;
    }
    .page__title {
        font-size: 3.25rem;
        margin-top: 0;
        margin-bottom: 0.1rem;
    }
    @media screen and (min-width: 64em) {
        .page__title {
            font-size: 3.25rem;
        }
    }
    @media screen and (min-width: 42em) and (max-width: 64em) {
        .page__title {
            font-size: 2.25rem;
        }
    }
    @media screen and (max-width: 42em) {
        .page__title {
            font-size: 1.75rem;
        }
    }
    .page__subtitle {
        margin-bottom: 2rem;
        font-weight: normal;
        opacity: 0.7;
    }
    @media screen and (min-width: 64em) {
        .page__subtitle {
            font-size: 1.25rem;
        }
    }
    @media screen and (min-width: 42em) and (max-width: 64em) {
        .page__subtitle {
            font-size: 1.15rem;
        }
    }
    @media screen and (max-width: 42em) {
        .page__subtitle {
            font-size: 1rem;
        }
    }
    :global(.portfolio__header) {
        position: absolute;
        color: white;
        width: 100%;
    }
    .container {
        width: 90%;
        max-width: 700px;
        margin: 0 auto;
    }
    .page__content {
        color: var(--text-color);
        font-size: 1.1rem;
        word-wrap: break-word;
    }
    @media (max-width: 42em) {
        .page__content {
            font-size: 1em;
        }
    }
    @media (min-width: 64em) {
        .page__content {
            font-size: 1.1em;
        }
    }
    .page__content :global(a) {
        color: var(--link-color);
        text-decoration: none;
        &:hover {
            text-decoration: underline;
        }
        &:visited {
            color: var(--link-visited-color, #551a8b);
        }
    }
    .page__content :global(ul) {
        list-style: none;
    }
    .page__content :global(li) {
        display: flex;
        gap: 1em;
        align-items: center;
        margin-left: -1.3em;
    }
    .project__time {
        margin-left: auto;
        white-space: nowrap;
    }
    .page__content :global(li::before) {
        content: "";
        height: 0.35em;
        width: 0.35em;
        display: block;
        background-color: currentColor;
        border-radius: 50%;
    }
    .page__content :global(:where(h1, h2, h3, h4)) {
        color: var(--accent-color);
    }
    :global(.portfolio__footer) {
        padding: 2rem;
        padding-top: 0;
    }
</style>
